package com.zx.controller.fileupload;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zx.service.fileupload.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author sunkai
 * @date 2022/8/27 0027 20:42
 * @mood zhou xun
 */
@Controller
@RequestMapping("/file/upload")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping(value = "/mvc/upload")
    public String upload(@RequestParam(value = "file") MultipartFile file,
                         HttpServletRequest request, Model model) throws IOException {
        String upload = fileUploadService.upload(file, request);
        String s = JSON.toJSONString(upload);
        model.addAttribute("file",s);
        return "home-setting-info";
    }
}
